import { defineStore } from 'pinia'
import { reqC1 ,reqC2,reqC3} from '@/api/product/attr'
import type { CategoryResponseData } from '@/api/product/attr/type'
import type { CategoryState } from './types/type'

const useCategoryStore = defineStore('Category', {
    state: (): CategoryState => {
        return {
            C1Info: [],
            C1Id: "",
            C2Info:[],
            C2Id: "",
            C3Info:[],
            C3Id: "",

        }
    },
    actions: {
        async getC1() {
            const res: CategoryResponseData = await reqC1()
            if (res.code == 200) {
                this.C1Info = res.data
            }
        },
        async getC2() {
            const res: CategoryResponseData = await reqC2(this.C1Id)
            if (res.code == 200) {
                console.log(res.data)
                this.C2Info = res.data
            }
        },
        async getC3() {
            const res: CategoryResponseData = await reqC3(this.C2Id)
            if (res.code == 200) {
                console.log(res.data)
                this.C3Info = res.data
            }
        }
    }
})

export default useCategoryStore